package com.ctbri.manage.compute.scala.calculate

import com.ctbri.manage.process.utils.DataProcessUtils
import org.apache.spark.sql.SparkSession
import org.slf4j.{Logger, LoggerFactory}

/**
 * @Author wangxuem
 * @create 2023/4/26 9:32
 */
object TemplateBaseChecker {

  protected final val logger: Logger = LoggerFactory.getLogger(this.getClass)
  def check(spark: SparkSession,configFile:String,outPutPath:String ): Unit = {
    val sql = new DataProcessUtils().getDynamicSqlFromTempFile(configFile)
    logger.warn("Spark sql: "+sql)
    val df = spark.sql(sql)
    df.show()
    logger.warn("生成稽核报表，数据条数为：" + df.count())
    df.cache()
    df.coalesce(1).write.option("header", "true").csv(outPutPath)
    logger.warn("生成的稽核报表，文件路径为:  "+outPutPath)
    logger.warn("执行完成~~~")
  }

}
